<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>静态方法之课程管理类</title>
</head>
<body>
    <script>
        let lesson = [
            {"name" : "mysql","price" : 189},
            {"name" : "javascript","price" : 169},
            {"name" : "css","price" : 99}
        ];

        class Lesson{
            constructor(data){
                this.data = data;
            }

            get price(){
                return this.data.price;
            }

            get name(){
                return this.data.name;
            }

            static createLessons(data){
                return data.map(item => {
                    return new this(item);
                })
            }

            // static maxPrice(data){
            //     return data.sort((a,b) => b.price - a.price)[0];
            // }

            static maxPrice(data){
                return data.reduce ((pre,value) => pre.price > value.price ? pre : value);
            }

            static totalPice(data){
                return data.reduce((total,val) => {
                    return total += val.price;
                },0);
            }
        }

        let lessons = Lesson.createLessons(lesson);
        console.log(Lesson.maxPrice(lessons).price);
        console.log(Lesson.maxPrice(lessons).name);
        console.log(Lesson.totalPice(lessons));
    </script>
</body>
</html>